package com.eascs.web.o2o.scheduler.task;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.vo.ModelResult;
import com.eascs.admin.o2o.loanAccount.service.IO2oCollectFeesService;
import com.eascs.admin.o2o.loanAccount.service.Io2oLoanapplyAccountService;
import com.eascs.admin.o2o.submitted.service.IO2oChargeSituationService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StopWatch;
import com.eascs.web.o2o.scheduler.service.PersonalAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component("accountTask")
public class AccountTask {

	protected final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	PersonalAccountService personalAccountService;
	@Reference
	Io2oLoanapplyAccountService o2oLoanapplyAccountService;

	@Reference
	IO2oCollectFeesService iO2oCollectFeesService;
	@Reference
	IO2oChargeSituationService iO2oChargeSituationService;
	/**
	 * @Title: bankAndprocess
	 * @Description: 创建个人账户
	 * @author 张庆奇
	 * @return void
	 * @throws @date
	 *             2017年11月28日 下午5:46:37
	 */
	@Scheduled(cron = "0 */1  * * * ?")
	public void createPersonalAccount() {
		StopWatch stopWatch = new StopWatch();
		logger.info("创建个人账户任务开始......,class:[{}]", this);
		personalAccountService.createPersonalAccount();
		logger.info("创建个人账户任务任务结束，共耗时：[{}]秒", stopWatch.elapsedTime() / 1000);
	}

	/**
	 * @Title: OpenLoanAccount
	 * @Description: 创建贷款单账户
	 * @author 余勇
	 * @return void
	 * @throws @date
	 *             2017年11月28日 下午5:46:37
	 */
	@Scheduled(cron = "0 */2  * * * ?")
	public void OpenLoanAccount() {
		StopWatch stopWatch = new StopWatch();
		logger.info("创建单款单账户任务开始......");
		o2oLoanapplyAccountService.OpenLoanAccount();
		logger.info("创建贷款单账户任务任务结束，共耗时：[{}]秒", stopWatch.elapsedTime() / 1000);
	}
	
	/**
	 * @Title: OpenLoanAccount
	 * @Description: 贷款单结清，划扣保证金
	 * @author 余勇
	 * @return void
	 * @throws @date
	 *             2017年12月12日 下午5:46:37
	 */
	@Scheduled(cron = "0 */5  * * * ?")
	public void LoanAccountBZJHK() {
		StopWatch stopWatch = new StopWatch();
		logger.info("贷款单结清，划扣保证金任务开始......");
		o2oLoanapplyAccountService.LoanAccountBZJHK();
		logger.info("贷款单结清，划扣保证金任务结束，共耗时：[{}]秒", stopWatch.elapsedTime() / 1000);
	}
	
	/**
	 * 	loan-12807	村镇放款扣费/	loan-12804	正常放款（非村镇放款） 
	 */
	@Scheduled(cron = "0 */2 * * * ?")
	public void queryListCharge() {
		logger.info("[service] [正常放款（非村镇放款）]任务[开始]......");
		StopWatch time = new StopWatch();
		try {
			ModelResult<Boolean> result = iO2oChargeSituationService.queryListCharge();
			logger.info("是否成功：【{}】，若不成功错误信息：【{}】", result.isSuccess(), result.getErrMsg());
		} catch (Exception e) {
			logger.info("异常原因：[{}]", e.getMessage());
		}
		logger.info("[service] [正常放款（非村镇放款）]任务[结束]......耗时：【{}】分", time.elapsedTime() / 1000 / 60);
	}
	
	/**
	 * 	loan-12807	村镇放款扣费/	loan-12804	正常放款（非村镇放款） 
	 */
	@Scheduled(cron = "0 */2 * * * ?")
	public void queryListCollectFee() {
		logger.info("[service] [村镇放款扣费]任务[开始]......");
		StopWatch time = new StopWatch();
		try {
			ModelResult<Boolean> result = iO2oCollectFeesService.queryListCollectFee();
			logger.info("是否成功：【{}】，若不成功错误信息：【{}】", result.isSuccess(), result.getErrMsg());
		} catch (Exception e) {
			logger.info("异常原因：[{}]", e.getMessage());
		}
		logger.info("[service] [村镇放款扣费]任务[结束]......耗时：【{}】分", time.elapsedTime() / 1000 / 60);
	}

}
